package top.kaoshanji.p1ch08a;

/**
 * 代码清单-p1ch08a-165页a：使用组合来复用代码
 * author kaoshanji
 * ^_^
 * create time 2025/3/9 15:00
 */
public class SprinklerSystem {

    private String value1, value2, value3, value4;

    // 这就是组合：持有其他对象的引用
    private WaterSource source = new WaterSource();
    private int i;
    private float f;

    @Override
    public String toString() {
        return "SprinklerSystem{" +
                "value1='" + value1 + '\'' +
                ", value2='" + value2 + '\'' +
                ", value3='" + value3 + '\'' +
                ", value4='" + value4 + '\'' +
                ", source=" + source +
                ", i=" + i +
                ", f=" + f +
                '}';
    }

    public static void main(String[] args) {
        SprinklerSystem sprinklers = new SprinklerSystem();
        System.out.println(sprinklers);
    }

}

class WaterSource {

    private String s;

    WaterSource() {
        System.out.println("WaterSource()");
        s = "Constructed";
    }

    @Override
    public String toString() {
        return s;
    }
}